package cn.jdy.plugins.admin;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.jdy.common.ctrl.BaseCtrl;
import cn.jdy.framework.log.BaseLog;
import cn.jdy.framework.util.DateUtil;
import cn.jdy.plugins.entity.OperateLog;
import cn.jdy.plugins.service.OperateLogService;

/**
 * 操作日志列表
 */
@Controller
@RequestMapping("/operateLog")
public class OperateLogCtrl extends BaseCtrl {

    @Autowired
    private OperateLogService operateLogService;

    @RequestMapping("/list")
    public ModelAndView list() {
        return new ModelAndView("/operate/operateLogList.jsp");
    }

/*    @RequestMapping("/delete/{id}")
    public ModelAndView delete(@PathVariable Long id) {
    	operateLogService.delete(id);
        return list();
    }*/

    /**
     *
     * @param operateLog
     * @param fromDate
     * @param toDate
     * @return
     */
    @RequestMapping("/queryByPage")
    @ResponseBody
    public Map<String, Object> queryByPage(OperateLog operateLog, String fromDate, String toDate) {
        return operateLogService.queryByPage(operateLog, fromDate, toDate);
    }
    
    
    @RequestMapping("/save")
    @ResponseBody
    public Map<String, Object> OperateLog(OperateLog operateLog){
      Map<String, Object> jsonMap = new HashMap<String, Object>();
      try {
    	  operateLog.setIp(request.getRemoteAddr());
    	  operateLog.setOpertime(DateUtil.getCurrentDate2());
    	  operateLogService.save(operateLog);
        jsonMap.put("status", 200);
      } catch (Exception e) {
        jsonMap.put("status", 500);
        BaseLog.e(this.getClass(), "保存操作日志信息失败", e);
      }
      return jsonMap;
    }
}
